package com.stgy.lease.web.admin.controller.apartment;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.stgy.lease.common.result.Result;
import com.stgy.lease.model.domain.ApartmentInfo;
import com.stgy.lease.model.domain.RoomInfo;
import com.stgy.lease.web.admin.dto.ApartmentInfoSaveDto;
import com.stgy.lease.web.admin.dto.ApartmentInfoSearchDto;
import com.stgy.lease.web.admin.service.ApartmentInfoService;
import com.stgy.lease.web.admin.service.RoomInfoService;
import com.stgy.lease.web.admin.vo.ApartmentDetailVo;
import com.stgy.lease.web.admin.vo.ApartmentInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName:ApartmentController
 * Package:com.stgy.lease.web.admin.controller
 * Description:
 *
 * @Author:helei
 * @Create:2024/8/31 - 10:49
 */
@RestController
@RequestMapping("/admin/apartment")
@Tag(name = "公寓管理模块")
public class ApartmentController {

    @Autowired
    private ApartmentInfoService apartmentInfoService;

    //http://localhost:5174/admin/apartment/saveOrUpdate POST
    @Operation(summary = "新增或更新公寓信息")
    @PostMapping("/saveOrUpdate")
    public Result<String> saveOrUpdate(@RequestBody ApartmentInfoSaveDto apartmentInfoSaveDto) {
        return Result.build(apartmentInfoService.saveOrUpdateApartmentInfoSaveDto(apartmentInfoSaveDto));
    }


    //http://localhost:5174/admin/apartment/pageItem?
    // current=1&size=10&provinceId=14&cityId=1403 GET
    @Operation(summary = "条件分页查询公寓列表")
    @GetMapping("/pageItem") //get没有请求体，直接用对象接收 pojo入参 接收请求参数
    public Result<Page<ApartmentInfoVo>> pageItem(ApartmentInfoSearchDto searchDto) {
        return Result.ok(apartmentInfoService.pageItem(searchDto));
    }

    //http://localhost:5174/admin/apartment/removeById?id=9 DELETE
    @Operation(summary = "根据id删除公寓信息")
    @DeleteMapping("/removeById")
    public Result<String> removeById(@RequestParam Long id) {
        return Result.build(apartmentInfoService.removeApartmentInfoById(id));
    }

    //ttp://localhost:5174/admin/apartment/getDetailById?id=9 GET
    @Operation(summary = "根据id获取公寓详细信息")
    @GetMapping("/getDetailById")
    public Result<ApartmentDetailVo> getDetailById(@RequestParam Long id) {
        return Result.ok(apartmentInfoService.getDetailById(id));
    }

    //http://localhost:5174/admin/apartment/listInfoByDistrictId?id=440306 GET
    @Operation(summary = "根据区域id获取该地区的公寓列表")
    @GetMapping("/listInfoByDistrictId")
    public Result<List<ApartmentInfo>> listInfoByDistrictId(@RequestParam("id") Long districtId) {
        return Result.ok(apartmentInfoService.getByDistrictId(districtId));
    }

    //http://localhost:5174/admin/apartment/updateReleaseStatusById?
    // id=1830404678916026369&status=1 POST
    @Operation(summary = "根据id更新公寓的发布状态")
    @PostMapping("/updateReleaseStatusById")
    public Result<String> updateReleaseStatusById(@RequestParam Long id,
                                                  @RequestParam Integer status){
        return Result.build(apartmentInfoService.updateReleaseStatusById(id,status));
    }

}